﻿<UserControl x:Class="DaxStudio.UI.Views.DocumentTabView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:avalondock="http://schemas.xceed.com/wpf/xaml/avalondock"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro.Platform"
             xmlns:local="clr-namespace:DaxStudio.UI.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <local:ActiveDocumentConverter x:Key="ActiveDocumentConverter"/>
        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <local:BoolToHiddenConverter x:Key="BoolToHiddenConverter"/>
    </UserControl.Resources>
    <Grid>
        <avalondock:DockingManager 
            x:Name="Items"
            ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
            
             >
            <!--
            <avalondock:DockingManager.Theme>
                <avalondock:GenericTheme />
            </avalondock:DockingManager.Theme>
            -->
            <!-- Note the Binding to "Content". This is how AvalonDock holds the model -->
            <!-- Header Template used for both solutions. Note that AvalonDock has default Templates itself -->
            
            <avalondock:DockingManager.DocumentHeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="4" FontFamily="Webdings" Width="10" Padding="0,3,0,0"
                                   Visibility="{Binding Converter={StaticResource BoolToHiddenConverter},Path=Content.IsQueryRunning}"
                                   />
                        <TextBlock Text="{Binding Content.DisplayName}"/>
                        <!-- 
                        <Button x:Name="DocumentCloseButton"
                                Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
                                Margin="5,0,0,0" Visibility="Visible" >
                            <Image Source="/AvalonDock;component/Images/PinClose.png"/>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <cal:ActionMessage MethodName="TabClosing">
                                        <cal:Parameter Value="{Binding Content}" />
                                    </cal:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                        -->
                    </StackPanel>
                </DataTemplate>
            </avalondock:DockingManager.DocumentHeaderTemplate>
<avalondock:DockingManager.DocumentPaneMenuItemHeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Content.DisplayName}"/>
                    </StackPanel>
                </DataTemplate>
            </avalondock:DockingManager.DocumentPaneMenuItemHeaderTemplate>
            <!-- This can be commented out in the Convention approach, as the Convention Manager has one incorporated -->
            <!--<avalondock:DockingManager.DocumentTemplate>
                <DataTemplate>
                    <ContentControl cal:View.Model="{Binding}" 
                                    VerticalContentAlignment="Stretch" 
                                    HorizontalContentAlignment="Stretch" 
                                    IsTabStop="False"/>
                </DataTemplate>
            </avalondock:DockingManager.DocumentTemplate>
-->
            
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="DocumentClosing">
                    <cal:ActionMessage MethodName="TabClosing">
                        <cal:Parameter Value="{Binding}" />
                        <cal:Parameter Value="$eventArgs" />
                    </cal:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            
        </avalondock:DockingManager >
    </Grid>
</UserControl>
